package filter

import (
	"anubis-framework/pkg/io"
	"gorm.io/gorm"
)

// 过滤器：删除阴线的股票
type BearishFilter struct {
	db *gorm.DB
}

// 初始化
func (b *BearishFilter) Init(db *gorm.DB) {
	b.db = db
}

// 执行
func (b *BearishFilter) DoFilter(transactionDate string) {
	io.Infoln("过滤器：删除阴线的股票，交易日期[%s]", transactionDate)
	b.db.Exec("delete from quant_stock_filter q where q.stock_code in ("+
		"select distinct t.stock_code from quant_stock_filter t join stock_transaction_data_all stda on stda.code_=t.stock_code and stda.date_=to_date(?,'yyyy-mm-dd') "+
		"where stda.close_price<stda.open_price)", transactionDate)
}
